import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import axios from 'axios';

class TableRow extends Component {

  constructor(props) {
        super(props);
        this.delete = this.delete.bind(this);
    }
    delete() {
        axios.delete('http://127.0.0.1:8000/overwork-signups/'+this.props.obj.id,
        {
          'headers': {
            'Authorization': 'Bearer ' + window.localStorage.getItem('access_token')
          }
        })
            .then(
              setTimeout(
                () => window.location.href = 'http://127.0.0.1:3000/index',
                700
              )
              )
            .catch(err => console.log(err))
    }
  render() {
    return (
        <tr>
        <td>
            {this.props.obj.user_id}
          </td>
          <td>
            {this.props.obj.user}
          </td>
          <td>
            {this.props.obj.work_start_at}
          </td>
          <td>
            {this.props.obj.work_end_at}
          </td>
          <td>
            {this.props.obj.rest_start_at}
          </td>
          <td>
            {this.props.obj.rest_end_at}
          </td>
          <td>
            {this.props.obj.content}
          </td>
          <td>
            <Link to={"/edit/"+this.props.obj.id} className="btn btn-sm btn-outline-primary">编辑</Link>
          </td>
          <td>
            <button onClick={this.delete} className="btn btn-sm btn-outline-danger">删除</button>
          </td>
        </tr>
    );
  }
}

export default TableRow;